home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Frameworks / MacZoop 1.6.5 / More Classes / Progress Dialog / ZProgress.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-17  |  4.5 KB  |  153 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            ObjectMacZapp        -- a standard Mac OOP application template
  5. *
  6. *
  7. *
  8. *            ZProgress.h            -- a progress dialog
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *            © 1996, Graham Cox
  15. *
  16. *
  17. *
  18. *
  19. *************************************************************************************************/
  20.  
  21. #pragma once
  22.  
  23. #ifndef __ZPROGRESS__
  24. #define    __ZPROGRESS__
  25.  
  26. #ifndef __ZDIALOG__
  27. #include    "ZDialog.h"
  28. #endif
  29.  
  30. // display types for the progress dialog- with "Cancel" button,
  31. // "Stop" button, or no button at all.
  32.  
  33. enum
  34. {
  35.     kCancelType,
  36.     kStopType,
  37.     kNoButton
  38. };
  39.  
  40. // display modes: normal or "stripey"
  41.  
  42. enum
  43. {
  44.     kProportionalProgress,
  45.     kIndeterminateProgress
  46. };
  47.  
  48. typedef short ProgType;
  49.  
  50. // progress class:
  51.  
  52. class    ZProgress : public ZDialog
  53. {
  54. protected:
  55.     short            theType;
  56.     long            max, value;
  57.     long             createTime, deferTime;
  58.     Rect            pRect;
  59.     Boolean            fAbort;
  60.     PixPatHandle    stripesPat;
  61.     ProgType        displayMode;
  62.  
  63. public:
  64.  
  65.     ZProgress(     ZCommander* aBoss,
  66.                 const short dialogID,
  67.                 const long maxValue,
  68.                 const short pType = kCancelType,
  69.                 const ProgType aMode = kProportionalProgress );
  70.  
  71.     ~ZProgress();
  72.  
  73. // progress bar manipulation:
  74.     virtual Boolean        InformProgress( const long progressSoFar );            // update the bar    
  75.     virtual void        SetDelay( const short delayTicks );                    // set deferment delay
  76.     virtual void        SetMessage( const Str255& aMsg );                    // pass message directly
  77.     virtual void        SetMessage( const short resID, const short index);    // uses 'STR#' resources
  78.  
  79. // dialog overrides
  80.     virtual void        SetUp();                                            // override
  81.     virtual void        ClickItem( const short theItem );                    // override
  82.     virtual void        DrawUserItem( const short item );                    // override
  83.     virtual Boolean        Filter( EventRecord* theEvent );                    // override
  84.     virtual void        OutlineDefaultItem() {};                            // override
  85.     virtual void        Draw();                                                // override
  86.  
  87. // new: Change display mode on the fly
  88.     virtual void        SetMode( ProgType aMode );                        
  89.     inline    ProgType    GetMode() { return displayMode; };
  90.  
  91. protected:
  92.     virtual void        CycleStripe();
  93. };
  94.  
  95.  
  96.  
  97. // this class is blindingly easy to use. To keep the user informed of progress, simply
  98. // create the object (maybe as a stack object in your lengthy routine), passing the
  99. // maximum number of iterations of your function. Then call InformProgress with the
  100. // loop count within that function. This will update the bar, etc. If the user hits the
  101. // cancel/stop button, this function will return FALSE, indicating that you should abort
  102. // the function, or TRUE normally, to indicate that you should carry on. In addition to
  103. // this, you can pass -1 in the <maxValue> parameter to indicate that you don't know how
  104. // long the function will take, in which case the bar is drawn with a striped pattern that
  105. // is animated on each call to InformProgress. Finally, you can defer the appearance of the
  106. // dialog for a specified delay period- call SetDelay to set the deferment time in ticks. In
  107. // any case the dialog will only get shown when you call InformProgress. Note that this class
  108. // handles events, etc as normal, so your lengthy routine is effectively made to cooperate
  109. // with everything else. You need to be aware of this and that current ports, devices, etc may
  110. // not remain set across calls to InformProgress. SetMessage is used to set the additional
  111. // string the dialog displays above the bar- you do not need to use it. You can also use the
  112. // SetTitle method (inherited from ZWindow) to set the title of the progress dialog.
  113.  
  114. // change, 27/5/97- the display modes are now separate, so you can switch from proportional
  115. // to striped bar and back without affecting the setting of either. This is to make the class
  116. // more versatile, and compatible with the forthcoming Appearance Mgr control.
  117.  
  118. // change, 27/5/97. The limitation that you can have only one progress dialog up at once is
  119. // removed, since there may be a need for multiple ones in multi-threaded applications. To make
  120. // this work well, you might like to consider using a modeless dialog for your progress
  121. // indicators.
  122.  
  123.  
  124. // pass in <maxValue> for striped bar:
  125.  
  126. #define        _STRIPED_BAR    -1
  127.  
  128. // typical delay times in ticks:
  129.  
  130. #define        kTwoSeconds        120
  131. #define        kThreeSeconds    180
  132.  
  133. // standard dialog resource IDs and items
  134.  
  135. #define        kStdProgressResID    133
  136.  
  137. #define        kCancelButton        1
  138. #define        kBarItem            2
  139. #define        kMessageItem        3
  140.  
  141. // pattern IDs used for bar ('ppat' resources)
  142.  
  143. #define        kStdBarPattern        129
  144. #define        kStdBackPattern        128
  145. #define        kStdStripedPattern    130
  146.  
  147. #define        kStopStringID        4
  148.  
  149. // errors:-
  150.  
  151. #define        kProgressAlreadyUpErr    222
  152.  
  153. #endif